package com.macasa.panel.entity.impl;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.hibernate.annotations.ForeignKey;

import com.google.common.base.Objects;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.IInterface;
import com.macasa.panel.entity.api.IXenVdsInterface;

@Entity
@Table(name = "xen_vds_interface")
@Getter
@Setter
@ToString
public class XenVdsInterface extends Interface implements IXenVdsInterface {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= -4443537636430882644L;

	@OneToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, targetEntity = com.macasa.panel.entity.impl.Interface.class)
	@JoinColumn(name = "fk_mapped_on_interface", nullable = false)
	@ForeignKey(name = "fk_xen_vds_interface_01")
	private IInterface			mappedOnInterface;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof XenVdsInterface)) {
			return false;
		}

		final XenVdsInterface other = CastHelpers.cast(obj, XenVdsInterface.class);

		return Objects.equal(this.mappedOnInterface, other.mappedOnInterface);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.mappedOnInterface);
	}
}
